package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.userPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * ClassName:userMapp
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/5/9 10:26
 * @Version 1.0
 */
@Mapper
public interface userMapp {
    @DS("baodingRussia")
    @Select("select * from russia_engine.user where userName=#{userName}")
    userPojo selectByName(String userName);
    //根据用户的输入，查询用户的权限
    @DS("baodingRussia")
    @Select("select ${field} from user where userName=#{user}")
    int fieldByOne(String field, String user);
    //根据用户的输入，各个字段通用
    @DS("baodingRussia")
    @Select("SELECT name,${filed} FROM user WHERE userName = #{userName}")
    userPojo problemUsePurview(String userName, String filed);
    //前端发来请求，按照用户的工号，查询用户名称和用户对应的页面权限
    @DS("baodingRussia")
    @Select("SELECT name,${queryFiledName} FROM user WHERE userName = #{userId}")
    userPojo useQueryPower(String queryFiledName, String userId);
    //查询所有的用户信息
    @DS("baodingRussia")
    @Select("select * from user")
    List<userPojo> queryAllUser();
    //修改一行数据
    @DS("baodingRussia")
    @Update("update user set " +
            "userName=#{userName}, " +
            "password=#{password}," +
            "name=#{name}," +
            "base=#{base}," +
            "pokayoke=#{pokayoke}," +
            "equipmentMaintain=#{equipmentMaintain}," +
            "problemManagement=#{problemManagement}," +
            "changeModel=#{changeModel}" +
            " where id=#{id}")
    void editOne(userPojo userPojo);
    //插入一整行
    @DS("baodingRussia")
    @Insert("insert into user " +
            "(problemManagement, pokayoke, userName, " +
            "password, name, equipmentMaintain, base)" +
            " VALUES" +
            " (#{problemManagement},#{pokayoke},#{userName}," +
            "#{password},#{name},#{equipmentMaintain},#{base})")
    void insertOne(userPojo userPojo);
    //根据id，修改某一个字段的值
    @DS("baodingRussia")
    @Update("update user set ${fieldName}=#{fieldVal} where id=#{id}")
    void editOneField(Integer id, String fieldName, String fieldVal);

    //查询一行用户信息
    @DS("baodingRussia")
    @Select("SELECT id, problemManagement, pokayoke, userName, name, " +
            "equipmentMaintain, base, componentGuideBook, controlTesting, changeModel, " +
            "operateGuideBook, controlPlan, systemDocument, equipmentManagement, " +
            "macTestCon, goodProductCondition, controlPlanNew, toExamineProblem, " +
            "workExceptionRemoval, suspectProductGuo " +
            "FROM user where ${fieldName}=#{fieldValue}")
    List<userPojo> queryUserListOneRow(String fieldName, String fieldValue);
}
